<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
      <el-form-item>
        <el-input v-model="dataForm.nickname" placeholder="昵称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.phone" placeholder="手机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="pushTime"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="中奖时间起"
          end-placeholder="中奖时间止"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column prop="winnerId" header-align="center" align="center" label="UID"></el-table-column>
      <el-table-column prop="nickname" header-align="center" align="center" label="昵称"></el-table-column>
      <el-table-column prop="avatar" header-align="center" align="center" label="头像">
        <template slot-scope="scope">
          <img :src="scope.row.avatar" style="width: 40px;height: 40px;">
        </template>
      </el-table-column>
      <el-table-column prop="phone" header-align="center" align="center" label="手机号"></el-table-column>
      <el-table-column prop="lotteryTime" header-align="center" align="center" label="中奖时间"></el-table-column>
      <el-table-column prop="prizeName" header-align="center" align="center" label="抽中奖品"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <div style="display: flex;justify-content: center;margin: 20px;">
      <el-button type="primary" @click="goBack">返回</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataForm: {
        nickname: "",
        phone:'',
      },
      page: this.pageIndex,
      limit: this.pageSize,
      key: "",
      pushTime: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListLoading1: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    };
  },
  props: ["id"],
  watch: {
    activityId() {
      return this.activityId;
    }
  },
  mounted() {
    this.getDataList();
  },
  methods: {
    search(){
      this.pageIndex = 1;
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let obj = {
        page: this.pageIndex,
        limit: this.pageSize,
        activityId: this.id
      };
      if (this.dataForm.nickname) {
        obj.nickname = this.dataForm.nickname;
      }
      if (this.dataForm.phone) {
        obj.phone = this.dataForm.phone;
      }
      if (this.pushTime.length > 0) {
        obj.startDate = this.pushTime[0];
        obj.endDate = this.pushTime[1];
      }
      this.$http({
        url: this.$http.adornUrl("/lotterySurvey/lotterylog/list"),
        method: "get",
        params: this.$http.adornParams(obj)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    goBack() {
      this.$emit("goBack");
    }
  }
};
</script>
<style scoped>
.tableTitle {
  padding: 20px;
  font-size: 15px;
}
.el-row {
  font-size: 16px;
  margin: 15px 0;
}
.centerel {
  text-align: center;
  padding: 10px 20px;
  background: #f2f2f2;
  margin: 25px 0;
}
.line {
  display: flex;
  justify-content: center;
}
.line div {
  height: 100%;
  width: 1px;
  background: #bbb;
}
</style>
